In [1]:
using ViscousFlow
In [2]:
using Plots
pyplot()
default(grid = false)
Set the flow parameters
In [3]:
Re = 1000; # Reynolds number
Set the free stream motion
In [4]:
U = 1.0; # Mean free stream velocity
σx = 0.4; # amplitude of velocity fluctuation
ϕ = -π/2 # phase lag of pitch to heave
fstar = 0.25/π # fc/U
K = π*fstar # reduced frequency, K = πfc/U
oscil = RigidBodyTools.OscilX(2π*fstar,U,U*σx,ϕ);
U∞ = RigidBodyMotion(oscil)
Out[4]:
Set up points on the body. Here is a plate:
In [5]:
n = 100;
body = Plate(1.0,n)
Out[5]:
In [6]:
cent = 1.0 + 1.0im
α₀ = -20*π/180 # angle of attack
T = RigidTransform(cent,α₀)
T(body) # transform the body to the current configuration
Out[6]:
Set up the domain
In [7]:
xlim = (0.0,4.0)
ylim = (0.0,2.0)
Out[7]:
In [8]:
plot(body,xlim=xlim,ylim=ylim)
Out[8]:
Now set up the coordinate data for operator construction
In [9]:
X = VectorData(body.x,body.y);
X̃ = VectorData(body.x̃,body.ỹ);
Set the domain size and time step size
In [11]:
Δx = 0.01;
Δt = min(0.5*Δx,0.5*Δx^2*Re);
Set up the state vector and constraint force vector for a static body
In [14]:
sys = NavierStokes(Re,Δx,xlim,ylim,Δt, X̃ = X, isstore = true)
Out[14]:
In [15]:
w₀ = Nodes(Dual,size(sys));
f = VectorData(X);
xg, yg = coordinates(w₀,dx=Δx,I0=origin(sys))
Out[15]:
Set up the integrator here
In [16]:
plan_intfact(t,u) = CartesianGrids.plan_intfact(t,u,sys)
plan_constraints(u,t) = ConstrainedSystems.plan_constraints(u,t,sys)
r₁(u,t) = ConstrainedSystems.r₁(u,t,sys,U∞)
r₂(u,t) = ConstrainedSystems.r₂(u,t,sys,U∞)
@time solver = IFHERK(w₀,f,sys.Δt,plan_intfact,plan_constraints,(r₁,r₂),rk=ConstrainedSystems.RK31)
Out[16]:
Initialize the state vector and the history vectors
In [17]:
t = 0.0
w₀ .= 0.0
u = deepcopy(w₀)
fx = Float64[];
fy = Float64[];
thist = Float64[];
uhist = [];
tsample = 0.2; # rate at which to store field data
Set the time range to integrate over.
In [18]:
tf = 1.0;
T = Δt:Δt:tf;
In [19]:
for ti in T
global t, u, f = solver(t,u)
push!(thist,t)
push!(fx,sum(f.u)*Δx^2)
push!(fy,sum(f.v)*Δx^2)
(isapprox(mod(t,tsample),0,atol=1e-6) || isapprox(mod(t,tsample),tsample,atol=1e-6)) ? push!(uhist,deepcopy(u)) : nothing
end
println("solution completed through time t = ",t)
Basic plot
In [20]:
plot(xg,yg,vorticity(uhist[end],sys),levels=range(-15,15,length=30), color = :RdBu,clim=(-15,15))
plot!(body)
Out[20]:
Make a movie
In [24]:
@gif for i = 1:length(uhist)
plot(xg,yg,vorticity(uhist[i],sys),levels=range(-15,15,length=30), color = :RdBu,clim=(-15,15))
plot!(body)
end
Out[24]:
In [23]:
px = plot(thist,2*fx,xlim=(0,Inf),ylim=(0,3),xlabel="Convective time",ylabel="\$C_D\$",legend=false)
py = plot(thist,2*fy,xlim=(0,Inf),ylim=(-3,3),xlabel="Convective time",ylabel="\$C_L\$",legend=false)
plot(px,py)
Out[23]: